<template>
  <div class="box">
    <div class="printButton">
      <el-button size="small" icon="el-icon-printer" @click="printer()"
        >打印</el-button
      >
    </div>
    <div class="searchLine">
      <div class="trainName">
        培训名称：
        <el-input
          v-model="inputName"
          class="inputBox"
          size="mini"
          clearable
        ></el-input>
      </div>
      <div class="trainType">
        培训类型：
        <el-select v-model="inputType" class="typeBox" size="mini">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </div>
      <div class="trainTime">
        培训时间：
        <el-date-picker
          class="dateBox"
          v-model="inputStart"
          type="date"
          size="mini"
          placeholder="选择日期"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
        至
        <el-date-picker
          class="dateBox"
          v-model="inputEnd"
          type="date"
          size="mini"
          placeholder="选择日期"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </div>
      <el-button
        size="small"
        icon="el-icon-search"
        style="height:30px"
        @click="printer()"
        >搜索</el-button
      >
    </div>
    <div class="table">
      <el-table
        ref="multipleTable"
        border
        :data="tableData"
        :cell-style="{ padding: '8px 0' }"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="40"> </el-table-column>
        <el-table-column label="培训名称" width="120" show-overflow-tooltip>
          <template slot-scope="scope">{{ scope.row.trainName }}</template>
        </el-table-column>
        <el-table-column prop="trainStart" label="培训开始时间" width="110">
        </el-table-column>
        <el-table-column prop="trainEnd" label="培训结束时间" width="110">
        </el-table-column>
        <el-table-column
          prop="trainType"
          label="培训类型"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="trainLocation"
          label="培训地点"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column prop="trainer" label="培训人" show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="trainerDepartment"
          label="培训人所在单位"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="trainerNum"
          label="培训人数"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="trainingContent"
          label="培训内容"
          show-overflow-tooltip
        >
        </el-table-column>
      </el-table>
    </div>
    <div class="pageChange">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[100, 200, 300, 400]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="400"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: "TrainingManagement",
  data() {
    return {
      inputName: "",
      inputType: "",
      inputStart: "",
      inputEnd: "",
      options: [
        {
          value: "选项1",
          label: "培训1"
        },
        {
          value: "选项2",
          label: "培训2"
        },
        {
          value: "选项3",
          label: "培训3"
        },
        {
          value: "选项4",
          label: "培训4"
        },
        {
          value: "选项5",
          label: "培训5"
        }
      ],
      tableData: [
        {
          trainName: "培训xx",
          trainStart: "2016-05-03",
          trainEnd: "2016-05-04",
          trainType: "培训1",
          trainLocation: "上海市普陀区金沙江路 1518 弄",
          trainer: "小明",
          trainerDepartment: "部分1",
          trainerNum: 10,
          trainingContent: "哈哈"
        },
        {
          trainName: "培训xx",
          trainStart: "2016-05-03",
          trainEnd: "2016-05-04",
          trainType: "培训1",
          trainLocation: "上海市普陀区金沙江路 1518 弄",
          trainer: "小明",
          trainerDepartment: "部分1",
          trainerNum: 10,
          trainingContent: "哈哈"
        },
        {
          trainName: "培训xx",
          trainStart: "2016-05-03",
          trainEnd: "2016-05-04",
          trainType: "培训1",
          trainLocation: "上海市普陀区金沙江路 1518 弄",
          trainer: "小明",
          trainerDepartment: "部分1",
          trainerNum: 10,
          trainingContent: "哈哈"
        }
      ],
      multipleSelection: [],
      currentPage: 1
    };
  },
  methods: {
    printer() {
      console.log(
        this.inputName,
        this.inputType,
        this.inputStart,
        this.inputEnd
      );
    },
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    }
  }
};
</script>

<style scoped>
.box {
  background: #eeeff1;
  border: 0.5px solid;
  border-color: rgba(0, 0, 0, 0.3);
  width: 1150px;
  height: 500px;
  margin-left: 30px;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.printButton {
  margin: 10px;
}
.searchLine {
  margin-left: 10px;
  width: 1000px;
  display: flex;
  justify-content: space-between;
}
.inputBox {
  width: 150px;
}
.typeBox {
  width: 140px;
}
.dateBox {
  width: 140px;
}
.table {
  margin-top: 10px;
  width: 100%;
}
.pageChange {
  position: absolute;
  bottom: 120px;
  margin-left: 10px;
}
</style>
